/*
 * myOffice.js
 * create by Charles Koh
 */

(function () {
	var menus = ["Community", "Account", "e-Wallet", "Transaction", "Genealogy", "Bonus/Reward"];
	var MyOfficePage = function () {
		this.naviEl = null;
		this.prevPage = null;
	};
	MyOfficePage.prototype = {
		handleEvent: function(event) {
			var target = event.target || event.srcElement;
			switch(event.type) {
				case 'click':
					var menu = target.contentId || target.title; //innerHTML.replace("&gt;", "");
					if (target.localName == 'span') {
						while (target.nextSibling)	target.parentNode.removeChild(target.nextSibling);
						target.parentNode.removeChild(target);
					}
					this.subPageIn(pgm.getMenuByTitleName(menu));
					break;
			}
		},
		createPage: function() {
			this.naviEl = document.getElementById("officePageNavi");
			var menu = pgm.getMenuByTitleName("myoffice");
			menu && this.subPageIn(menu);
		},
		subPageIn: function(menu) {
			
			//-- menu --//
			var div = document.getElementById("my_office_menu");
			var span = document.createElement("span");
			span.innerHTML = ">" + menu.title;
			span.contentId = menu.contentId;
			span.title = menu.title;
			this.naviEl.appendChild(span);
			addEvent(span, 'click', this, false);
			div.innerHTML = ''; //'<label>' + menu.title + '</label><ol>';
			
			if (this.prevPage) 
				this.prevPage.style["display"] = "none";
			if (menu.contentId) {
				this.prevPage = document.getElementById(menu.contentId);
				if (this.prevPage)
					this.prevPage.style["display"] = "block";
				//else{}	
			}
			if (menu.menus) {
				var ol = document.createElement('ol');
				
				for (var i=0, len=menu.menus.length; i<len; i++) {
					var li = document.createElement('li');
					li.innerHTML = menu.menus[i].title;
					li.contentId = menu.menus[i].contentId;
					li.title = menu.menus[i].title;
					addEvent(li, 'click', this, false);
					ol.appendChild(li);
				}
				div.appendChild(ol);
			}
			
			//-- content --//
			
		}
		
	};

	if (typeof exports !== 'undefined') exports.MyOfficePage = MyOfficePage; 
	else window.MyOfficePage = MyOfficePage;
})();
